<?php

require_once '../mysqlConnect.php';
$files = glob("../Model/*.php");
foreach ($files as $file)
require_once "$file";


function fetchICDObjects($patId) {

	$DBH = GetPDOConnection();
	$sql = "SELECT icd_nine_entry.*, icd_codes.id as icd_id, icd_codes.code, icd_codes.name FROM icd_nine_entry JOIN icd_codes ON icd_nine_entry.code_id = icd_codes.id WHERE patient_id = :patId ORDER BY date_given DESC";
	
	try {
		$STH = $DBH->prepare($sql);
		$STH->setFetchMode(PDO::FETCH_ASSOC);
		$STH->bindValue(":patId", $patId);
		$STH->execute();
		$result = $STH->fetchAll();
		$DBH = null;
		return $result;
	} catch (PDOException $e) {
		return "Can't query database for ICD9 Codes: " . $e->getMessage();
	}
}

function retrieveAllICDObjects() {

	$DBH = GetPDOConnection();
	$sql = "SELECT * FROM icd_codes ORDER BY code";

	try {
		$STH = $DBH->prepare($sql);
		$STH->setFetchMode(PDO::FETCH_CLASS, "Icd_Code");
		$STH->execute();
		$result = $STH->fetchAll();
		return $result;
	} catch (PDOException $e) {
		$ValidationErrors = "Can't query database for ICD9 Codes: " . $e->getMessage();
	}
}